package com.tj.collection.db.admin.dao.impl;

import com.tj.collection.common.old.BaseDAOImpl;
import com.tj.collection.db.admin.dao.AuthAdminProductDao;
import com.tj.collection.db.admin.entity.AuthAdminProductEntity;
import com.tj.collection.db.admin.entity.AuthAdminProductEntityConditions;
import com.tj.collection.db.admin.dao.mp.AuthAdminProductEntityMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * User: fenqiguanjia
 * Date: 2017-07-24
 * Time: 20:14:58.004
 */

@Repository
public class AuthAdminProductDaoImpl extends BaseDAOImpl<AuthAdminProductEntity, Long, AuthAdminProductEntityConditions> implements AuthAdminProductDao {

    @Autowired
    private AuthAdminProductEntityMapper authAdminProductEntityMapper;

    @Override
    @Autowired
    public void setBaseMapper() {
        super.setBaseMapper(authAdminProductEntityMapper);
    }


    @Override
    public List<AuthAdminProductEntity> getListByAdminId(Long adminId) {
        AuthAdminProductEntityConditions conditions = new AuthAdminProductEntityConditions();
        AuthAdminProductEntityConditions.Criteria criteria = conditions.createCriteria();

        criteria.andAdminIdEqualTo(adminId);

        return authAdminProductEntityMapper.selectByExample(conditions);
    }

    @Override
    public Boolean deleteByAdminId(Long adminId) {
        AuthAdminProductEntityConditions conditions = new AuthAdminProductEntityConditions();
        AuthAdminProductEntityConditions.Criteria criteria = conditions.createCriteria();

        criteria.andAdminIdEqualTo(adminId);

        return authAdminProductEntityMapper.deleteByExample(conditions) > 0;
    }

    /**
     * 根据产品类目获取adminId
     *
     * @param productType
     * @return
     */
    @Override
    public List<AuthAdminProductEntity> getAuthAdminProductEntityListByProductType(String productType) {
        AuthAdminProductEntityConditions conditions = new AuthAdminProductEntityConditions();
        AuthAdminProductEntityConditions.Criteria criteria = conditions.createCriteria();
        if (StringUtils.isNotBlank(productType)) {
            criteria.andProductTypeLike("%" + productType + "%");
        }

        return authAdminProductEntityMapper.selectByExample(conditions);
    }
}